import {Toast,Loading} from "../../utils/util";
Page({
  data:{},
  backRegister() {
    wx.navigateTo({
      url: '../zhuce/zhuce',
    })
  },
  formSubmit(e) {
    let formDate = e.detail.value;
      for(var i in formDate){
        if(formDate[i] == ''){
          const msg = i == 'zhanghao' ? '用户名':'密码';
          Toast("error",msg+"不能为空");
          return;
        }
      }
      console.log(formDate)
      wx.cloud.database().collection('user').where({
        zhanghao: formDate['zhanghao'],
        mima: formDate['mima'],
    }).get({
      async success(res){
        console.log(res)
        if(res.data.length > 0){
          wx.setStorageSync('userInfo', { ...res.data[0] })
          wx.setStorageSync('uid', res.data[0]._id)

          const dict = await wx.cloud.database().collection('dictionary').get()
          wx.setStorageSync('dictList', dict.data)

          wx.switchTab({
            url: '../index/index',
          })
        }else{
          Toast("none","用户不存在,请重新登录");
        }
      }
      })
  },
  jump(){
    wx.navigateTo({
      url: '../zhuce/zhuce',
    })
  }
})